local skel = fk.CreateSkill {
  name = "#rmt_bow_skill",
  attached_equip = "rmt_bow",
}

Fk:loadTranslationTable{
  ["#rmt_bow_skill"] = "神机连弩",
  ["#rmt_bow-slash"] = "神机连弩：你可以对目标再使用【杀】",
}

skel:addEffect(fk.CardUseFinished, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) and data.card.trueName == "slash" then
      return data.tos and table.find(data.tos, function (to)
        return not to.dead
      end)
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    -- 每个目标单独查询概率
    local toIds = {}
    for _, to in ipairs(data.tos) do
      if not to.dead then
        local dist = player:distanceTo(to)
        if dist > 0 and dist < 5 then
          local rat = 1 - 0.25 * (dist - 1)
          if rat == 1 or math.random() < rat then
            table.insert(toIds, to.id)
          end
        end
      end
    end
    local use
    if #toIds > 0 then
      use = room:askToUseCard(player, {
        pattern = "slash", skill_name = skel.name, cancelable = true, prompt = "#rmt_bow-slash",
        extra_data = { bypass_distances = true, bypass_times = true, exclusive_targets = toIds }
      })
    end
    if not use or #use.tos == 0 then
      player:addSkillUseHistory(skel.name, -1) -- 后悔发动，其实用处不大
      return
    end
    -- 连弩效果
    room:broadcastPlaySound("packages/standard_cards/audio/card/crossbow")
    room:sendLog{
      type = "#InvokeSkillTo",
      from = player.id,
      arg = skel.name,
      to = table.map(use.tos, Util.IdMapper),
    }
    room:setEmotion(player, "packages/standard_cards/image/anim/crossbow")
    use.extraUse = true
    room:useCard(use)
  end,
})


return skel
